package logic

import (
	"context"
	"yuekaoHouse/house_srv/model/mysql"

	"yuekaoHouse/house_srv/house"
	"yuekaoHouse/house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListAddressLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListAddressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListAddressLogic {
	return &HouseListAddressLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListAddressLogic) HouseListAddress(in *house.HouseListAddressRequest) (*house.Houses, error) {
	// todo: 房源地区查询

	h := mysql.House{}

	err := h.HouseFindListByAddress(in.Address)
	if err != nil {
		logx.Error("地区查询失败", err)
		return nil, err
	}

	return &house.Houses{
		Title:   h.Title,
		Price:   float32(h.Price),
		Address: h.Address,
		MiaJi:   float32(h.MiaJi),
		Avatar:  h.Avatar,
		Mobile:  h.Mobile,
	}, nil
}
